package com.tgy.JUC.BlockingQueueDemo;

import java.util.concurrent.ArrayBlockingQueue;

/***
 * @ClassName: Test1
 * @Description: BlockingQueue 测试 抛出异常
 * @Auther: 送你一块二向箔
 * @Date: 17:14 2022/3/11
 * @version : V1.0
 */
public class Test1 {
    public static void main(String[] args) {
        run2();
    }
    public static void run1(){
        ArrayBlockingQueue<String> strings = new ArrayBlockingQueue<>(3);
        System.out.println(strings.add("a"));
        System.out.println(strings.add("b"));
        System.out.println(strings.add("c"));
        //超出范围异常IllegalStateException
        System.out.println(strings.add("d"));
    }

    //多取了 NoSuchElementException
    public static void run2(){
        ArrayBlockingQueue<String> strings = new ArrayBlockingQueue<>(1);
        System.out.println(strings.add("a"));
        System.out.println(strings.remove());
        System.out.println(strings.remove());

    }
}
